program Ising2dProject
    use ifport  ! biblioteki do liczb losowych
    use modinip ! zarzadza wczytywaniem danych
    use modising2d
    implicit none

    integer :: i,iter
    double precision :: T
    character(len=11) :: plik

    call ising_wczytaj_parametry("config.ini")
    call ising_alokuj_pamiec()

    print *, 'Rozpoczecie obliczen'
    call ising_inicjalizuj_siec(1.0D0)
    print*,"energy=",l_params%energy
    print*, "no_rec:",l_params%no_rejections
    iter = 1
!    do T = 5.2 , 1.0 , -0.1
!        g_params%T = T
!
!
!
!        call ising_cycle(1000,50)
!        print*,T,l_params%acc_ratio
!        write(334,"(20e20.8)"),g_params%T,l_params%Cw,l_params%Xi,abs(l_params%mean_magnetization),l_params%acc_ratio
!
!        plik = ""
!        if(iter < 10) then
!            write(plik(1:1),"(i1)"),iter
!            plik(2:9) = "-ave.txt"
!        else if(iter < 100) then
!            write(plik(1:2),"(i2)"),iter
!            plik(3:10) = "-ave.txt"
!        else if(iter < 1000) then
!            write(plik(1:3),"(i3)"),iter
!            plik(4:11) = "-ave.txt"
!        endif
!        print*,"dane/"//plik
!        call ising_zapisz_do_pliku("dane/"//plik,ZAPISZ_SREDNIA_SIEC)
!        iter = iter +  1
!    enddo

    do T = 2.3 ,1.9, -0.01
        g_params%T = T
        print*,T
        call ising_cycle(30000,50)
        write(332,"(20e20.8)"),g_params%T,l_params%Cw,l_params%acc_ratio, l_params%Xi, l_params%mean_magnetization, l_params%mean_sqr_magnetization
    enddo
!        call ising_cycle(1000,50)

    g_params%T = 2.0
!    call ising_cycle(10000,50)

    print*,"acc_ratio=",l_params%acc_ratio
    !call ising_zapisz_do_pliku("siec.txt",ZAPISZ_SIEC)
    !call ising_zapisz_do_pliku("avesiec.txt",ZAPISZ_SREDNIA_SIEC)
    !call ising_zapisz_do_pliku("podsiec.txt",ZAPISZ_PODSIEC)
    call ising_zapisz_przekroj_X("przekroj.txt",g_params%nx/2)
    open(unit = 333, file= "DaneT.txt" )
        write(333,"(20e20.8)"),g_params%T,l_params%Cw,l_params%acc_ratio,l_params%energy
    close(333)
! Todo:
! - wolff
! - Magnetyzacja , Chi

    call ising_dealokuj_pamiec()

    ! *********************************************************** !
    !                           FUNKCJE                           !
    ! *********************************************************** !
    contains






end program Ising2dProject

